Skip to content

Add Computus in Javascript and Typescript #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hugo-s29
Copy link
Contributor

A translation of the computus Julia code in javascript and in typescript.

Comment on lines 15 to 30
const a = year % 19;

// Century index
const k = Math.floor(year / 100);

// Shift of metonic cycle, add a day offset every 300 years
const p = Math.floor((13 + 8 * k) / 25);

// Correction for non-observed leap days
const q = Math.floor(k / 4);

// Correction to starting point of calculation each century
const M = mod(15 - p + k - q, 30);

// Number of days from March 21st until the full moon
const d = (19 * a + M) % 30;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you aren't explicitly typing these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explicitly type these variables to be clearer to read.
However, it may be better with types: if someone wants an implementation without types, they could use the JavaScript version.
I'll add types to every variable as soon as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thanks!

Comment on lines 46 to 47
// Historical corrections for April 26 and 25
if (e === 6) if (d === 29 || (d === 28 && a > 10)) e = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind bringing the reassignment into its own line? It's a bit buried at the end as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can fix that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, would you mind doing that for all instances of inline if/else

@Amaras Amaras added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Aug 21, 2021
@@ -320,6 +320,10 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
[import, lang:"lisp"](code/clisp/gauss-easter.lisp)
{% sample lang="nim" %}
[import, lang:"nim"](code/nim/gauss_easter.nim)
{% sample lang="javascript" %}
[import, lang:"nim"](code/javascript/gauss_easter.js)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also need to change the lang "variable" to JavaScript and TypeScript. I forgot to do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, I missed this as well

@hugo-s29
Copy link
Contributor Author

hugo-s29 commented Aug 23, 2021

I added types to the typescript code and changed the formatting for javascript and typescript.
Also, I added a Dart implementation.

@Amaras
Copy link
Member

Amaras commented Aug 23, 2021

I think you're trying to go a little too fast with the PRs. 😅
I'd recommend separating your Dart implementation from the TypeScript and JavaScript ones, because I don't know if we have competent Dart reviewers, so that might prevent your current PR from getting merged.
It's not really that important for the Computus because it's so simple, but keep that in mind in the future.

@leios
Copy link
Member

leios commented Aug 24, 2021

Since you are a first time contributor, feel free to add your name to the list in CONTRIBUTORS.md.

Also: Dart seems to be a new language in the AAA, could you add a section to the book.json and make sure syntax highlighting is correct? It should be, but it would be nice to double-check!

@leios
Copy link
Member

leios commented Aug 24, 2021

For this PR, the implementation is so straightforward, that I feel it is ok to merge Dart as long as it produces the right results; however, definitely split it in future PRs.

Thanks again for the submission!

@ntindle
Copy link
Member

ntindle commented Aug 24, 2021

JS Output:
JS Output
TS Output:
TS Output

@ntindle
Copy link
Member

ntindle commented Aug 24, 2021

Dart output:
Dart Output

@ntindle
Copy link
Member

ntindle commented Aug 24, 2021

Note still needs lang highlighting for dart like #839 book.json

@hugo-s29 hugo-s29 force-pushed the computus_in_javascript_typescript branch from c17ed01 to 48b52eb Compare August 24, 2021 17:50
Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @ntindle is okay with it, I think it's okay with me.

@hugo-s29
Copy link
Contributor Author

I added my name to the CONTRIBUTORS.md and added the Dart language to the book.json.
The syntax highlighting for Dart is working, I checked it.

Also, contents/convolutions/res/Sobel_filters.png and contents/convolutions/res/sobel_filters.png were conflicting when working on Windows, so I had to delete one.

About the Dart implementation, I could have created another PR. Sorry about that.

@Amaras
Copy link
Member

Amaras commented Aug 24, 2021

Right, I think we didn't consider Windows' path system. From manual inspection, it looks like they are the same images, though, so I don't think it's that much of a problem. We'll have to see what breaks, and make sure there are no case-dependant paths in the AAA any more for future-proofing it.
Apart from the conflicting images, I don't have anything against your PR, I think it's ready to merge.
I think I'll let someone else merge this PR, because we'll probably try to re-include the missing image before merging, and I'm not entirely competent. 😅

Maybe you could open an issue and/or a PR to correct the name conflict problem, if you feel like it. It would be appreciated. 😉

@hugo-s29
Copy link
Contributor Author

It seems the only file referencing this image is contents/convolutions/2d/2d.md and it only uses sobel_filters.png. I'll open a pull request for that.
Otherwise, I've readded the missing file.

@Amaras Amaras merged commit a913874 into algorithm-archivists:master Aug 24, 2021
@hugo-s29 hugo-s29 deleted the computus_in_javascript_typescript branch August 24, 2021 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants